package com.lwy.goods.controller;

import com.github.pagehelper.PageInfo;
import com.lwy.common.Result;
import com.lwy.common.StatusCode;
import com.lwy.goods.pojo.TbBrand;
import com.lwy.goods.service.impl.BrandServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

//品牌controller控制层
@RestController
@RequestMapping("brand")
public class BrandController {

    @Resource
    BrandServiceImpl  brandService;

    //分页查询列表
    @RequestMapping("list")
    public Result<PageInfo<TbBrand>> list(String name,Integer pageNum, Integer pageSize){
        PageInfo<TbBrand> page = brandService.page(name,pageNum, pageSize);
        return new Result<PageInfo<TbBrand>>(true, StatusCode.OK,"品牌查询",page);
    }

//    新增
    @RequestMapping("save")
    public Result<List<TbBrand>> save(TbBrand tbBrand) throws ParseException {
        int save = brandService.saveTbBrand(tbBrand);
        return new Result<List<TbBrand>>(true, StatusCode.OK,"品牌新增",save);
    }

//    修改
    @RequestMapping("edit")
    public Result<List<TbBrand>> edit(TbBrand tbBrand) throws ParseException {
        boolean update = brandService.updateById(tbBrand);
        return new Result<List<TbBrand>>(true, StatusCode.OK,"品牌编辑",update);
    }

//    返回
    @RequestMapping("findId")
    public TbBrand findId(Integer tid){
        return brandService.getById(tid);
    }

//    删除
    @RequestMapping("del")
    public Result<List<TbBrand>> del(Integer id){
        boolean del = brandService.removeById(id);
        return new Result<List<TbBrand>>(true, StatusCode.OK,"删除",del);
    }

    //    @RequestMapping("save")
//    public int save(TbBrand tbBrand) throws ParseException {
//        return brandService.saveTbBrand(tbBrand);
//    }
//
//    @RequestMapping("edit")
//    public boolean edit(TbBrand tbBrand) throws ParseException {
//        return brandService.updateById(tbBrand);
//    }
//    @RequestMapping("findId")
//    public TbBrand findId(Integer tid){
//        return brandService.getById(tid);
//    }
}
